package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.data.Result;
import com.dongdongshop.em.ConstantEnum;
import com.dongdongshop.pojo.Cart;
import com.dongdongshop.pojo.TbOrder;
import com.dongdongshop.pojo.TbOrderItem;
import com.dongdongshop.pojo.TbUser;
import com.dongdongshop.service.TbOrderItemService;
import com.dongdongshop.service.TbOrderService;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("order")
public class OrderController {


    @Reference
    private TbOrderItemService orderItemService;

    @Reference
    private TbOrderService orderService;

    @RequestMapping("toOrder")
    @ResponseBody
    public Result toOrder(){
        TbUser user = (TbUser) SecurityUtils.getSubject().getPrincipal();
        if (user == null){
            return Result.build(ConstantEnum.NOT_LOG);
        }
        return Result.build(ConstantEnum.SUCCESS);
    }

    @RequestMapping("findOrderPayList")
    @ResponseBody
    public Result selectOrderSend(String status){

        TbUser user = (TbUser) SecurityUtils.getSubject().getPrincipal();
        List<Cart> cartList = orderItemService.findOrderPayList(user,status);
        return Result.build(ConstantEnum.SUCCESS).setResult(cartList);

    }
}
